﻿Imports System.Collections.ObjectModel
Imports PTIC_Util
Imports PTIC_GestionBDD
Imports OMANE.Common.Model.Interfaces

Public Class ReferentielOMANE
    Implements IReferentielOMANE

    Private m_ListeTraitements As ListeTraitementsBase(Of String)

    Public Sub New(ByVal ListeTraitements As ListeTraitementsBase(Of String))
        m_ListeTraitements = ListeTraitements
        Initialize_InfoTables()
        Initialize_TablesMortalite()
        Initialize_TablesMaintienINCINV()
        Initialize_TablesMaintienINCINV_Fra()
        Initialize_TablesMaintienINCINV_Tx()
    End Sub

#Region "Liste de toutes les tables"
    Private Sub Initialize_InfoTables()
        Dim ConnectionListeTablesReferentiel As New OleDb.OleDbConnection( _
            "Provider=Microsoft.Jet.OLEDB.4.0;" & _
            "Data Source=" & csteFichSynthReferentiel & ";" & _
            "Extended Properties=""Excel 8.0;HDR=YES;""")

        Dim tbleListeTbleRef As New tableBDD_Excel("refListeTableRef", _
                                                   New Cla_NomFichier(csteFichSynthReferentiel), _
                                                   ConnectionListeTablesReferentiel)
        tbleListeTbleRef.NomTableDansBDD = "refTables"
        tbleListeTbleRef.Calculer_DataTable()

        Dim DataTableReferentiel As DataTable = tbleListeTbleRef.DataTableResultat

        Dim TablesReferentiel As New List(Of IInfoTableReferentiel)
        For Each Row As DataRow In DataTableReferentiel.Rows
            Dim TableReferentiel As New InfoTableReferentiel(Row("strNomTable"),
                                                             Row("strTypeTable"),
                                                             Row("strNomFichier"),
                                                             Row("strDescriptionTable"))
            TablesReferentiel.Add(TableReferentiel)
        Next

        m_ReadOnlyTables = New ReadOnlyCollection(Of IInfoTableReferentiel)(TablesReferentiel)
    End Sub
    Private m_ReadOnlyTables As ReadOnlyCollection(Of IInfoTableReferentiel)
    Public ReadOnly Property InfoTables As System.Collections.ObjectModel.ReadOnlyCollection(Of IInfoTableReferentiel) Implements IReferentiel.InfoTables
        Get
            Return m_ReadOnlyTables
        End Get
    End Property
#End Region

#Region "Tables de mortalité"
    Private Sub Initialize_TablesMortalite()
        Dim ReadOnlyTablesMort As ReadOnlyCollection(Of IInfoTableReferentiel) = New ReadOnlyCollection(Of IInfoTableReferentiel)(
            (From infoTable As IInfoTableReferentiel In m_ReadOnlyTables
            Select infoTable
            Where infoTable.TypeTable = "DC").ToList)
        m_TablesMortalite = New ReferentielTablesMortalite(ReadOnlyTablesMort, m_ListeTraitements)
    End Sub
    Private m_TablesMortalite As IReferentielTablesMortalite    'Contient la liste des tables, et une factory pour obtenir les objets typés
    Public ReadOnly Property TablesMortalite As Interfaces.IReferentielTablesMortalite Implements Interfaces.IReferentielOMANE.TablesMortalite
        Get
            Return m_TablesMortalite
        End Get
    End Property
#End Region

#Region "Tables de maintien INCINV"
    Private Sub Initialize_TablesMaintienINCINV()
        Dim ReadOnlyTablesINCINV As ReadOnlyCollection(Of IInfoTableReferentiel) = New ReadOnlyCollection(Of IInfoTableReferentiel)(
            (From infoTable As IInfoTableReferentiel In m_ReadOnlyTables
            Select infoTable
            Where infoTable.TypeTable = "MAINTINCINV_NB_MENS").ToList)
        m_TablesINCINV = New ReferentielTablesMaintienINCINV(ReadOnlyTablesINCINV, m_ListeTraitements)
    End Sub
    Private m_TablesINCINV As IReferentieTablesINCINV    'Contient la liste des tables, et une factory pour obtenir les objets typés
    Public ReadOnly Property TablesINCINV As Interfaces.IReferentieTablesINCINV Implements Interfaces.IReferentielOMANE.TablesINCINV
        Get
            Return m_TablesINCINV
        End Get
    End Property
#End Region

#Region "Tables INCINV _ FRA"    'Contient la liste des tables, et une factory pour obtenir les objets typés
    Private Sub Initialize_TablesMaintienINCINV_Fra()
        Dim ReadOnlyTablesINCINV_Fra As ReadOnlyCollection(Of IInfoTableReferentiel) = New ReadOnlyCollection(Of IInfoTableReferentiel)(
            (From infoTable As IInfoTableReferentiel In m_ReadOnlyTables
            Select infoTable
            Where infoTable.TypeTable = "FRAINCINV").ToList)
        m_TablesINCINV_Fra = New ReferentielTablesMaintienINCINV_Fra(ReadOnlyTablesINCINV_Fra, m_ListeTraitements)
    End Sub
    Private m_TablesINCINV_Fra As IReferentielTablesINCINV_Fra
    Public ReadOnly Property TablesINCINV_Fra As Interfaces.IReferentielTablesINCINV_Fra Implements Interfaces.IReferentielOMANE.TablesINCINV_Fra
        Get
            Return m_TablesINCINV_Fra
        End Get
    End Property
#End Region

#Region "Tables INCINV _ Tx"    'Contient la liste des tables, et une factory pour obtenir les objets typés
    Private Sub Initialize_TablesMaintienINCINV_Tx()
        Dim ReadOnlyTablesINCINV_Tx As ReadOnlyCollection(Of IInfoTableReferentiel) = New ReadOnlyCollection(Of IInfoTableReferentiel)(
            (From infoTable As IInfoTableReferentiel In m_ReadOnlyTables
            Select infoTable
            Where infoTable.TypeTable = "MAINTINCINV").ToList)
        m_TablesINCINV_Tx = New ReferentielTablesMaintienINCINV_Tx(ReadOnlyTablesINCINV_Tx, m_ListeTraitements)
    End Sub
    Private m_TablesINCINV_Tx As IReferentielTablesINCINV_Tx
    Public ReadOnly Property TablesINCINV_Tx As Interfaces.IReferentielTablesINCINV_Tx Implements Interfaces.IReferentielOMANE.TablesINCINV_Tx
        Get
            Return m_TablesINCINV_Tx
        End Get
    End Property
#End Region

End Class